<?php

/*
 * Action 4$
 *
 * +1 Card
 * +1 Action
 * Gain a Rats. Trash a card from your hand other than a Rats (or reveal a hand of all Rats).
 * When you trash this, +1 Card
 */

class Rats extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Rats", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 card",
            "+1 Action",
            "Gain a Rats. Trash a card from your hand other than a Rats (or reveal a hand of all Rats).",
            "When you trash this, +1 Card");
    }

    public function getDisplayName($quantity = 1) {
        if ($quantity == 1) {
            return "Rats";
        }
        return $quantity . " Rats";
    }

    public function trash(Game $game, $name) {
        $drawed_cards = $game->drawCards(1, $name);
        ScreenDisplay::addScreenMessage($game, true, "draw  " . nicePrint($drawed_cards), "draws " . sizeof($drawed_cards) . " cards", $name);
        $game->setTempCard($this);
        $game->cardTrashFinished($name);
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        $drawed_cards = $game->drawCards(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action, draw  " . nicePrint($drawed_cards), "gets +1 action,  draws " . sizeof($drawed_cards) . " cards");

        $rats = $game->moveCardFromPileToPile("Rats", BoardCards, DiscardPile);
        ScreenDisplay::addScreenMessage($game, false, " and gain  " . nicePrint($rats), " and gains " . ScreenDisplay::$LMSG);

        $playHand = $game->getPlayHand();
        $not_rats = array();
        foreach ($playHand as $card) {
            if (!$card instanceof Rats) {
                $not_rats[] = $card;
            }
        }

        if (sizeof($not_rats) == 0) {
            ScreenDisplay::addScreenMessage($game, false, ", trash nothing and reveal " . nicePrint($playHand), ", trashes nothing and reveals " . ScreenDisplay::$LMSG);
        } else {
            $not_rats = getUniqueCards($not_rats);
            if (sizeof($not_rats) > 1) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $not_rats, 1, 1, null, "Choose a card to trash");
                $old_card_name = $output[0];
            }
            else {
                $old_card_name = $not_rats[0];
            }
            $old_card = $game->moveCardFromPileToPile($old_card_name, PlayHand, Trash);
            ScreenDisplay::addScreenMessage($game, false, " and trash " . nicePrint($old_card), " and trashes " . ScreenDisplay::$LMSG);
        }
        $game->cardActionFinished();
        return true;
    }

}

?>